const { contextBridge, ipcRenderer } = require("electron")
const fs = require('fs')

contextBridge.exposeInMainWorld('preloadApi', {
  save(content) {
    ipcRenderer.invoke('showSaveDialog').then(pathUrl => {
      if (pathUrl) {
        pathUrl = pathUrl + '.txt'
        fs.writeFile(pathUrl, content, 'utf-8', (err, data) => {
          if (err) return console.log(err)
          alert('保存成功')
        })
      }
    })
  }
})